<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "mkt_gold".
 *
 * @property string $id
 * @property string $user_id
 * @property string $amount
 * @property string $memo
 * @property string $create_time
 * @property integer $source
 */
class MktGold extends \yii\db\ActiveRecord
{
    const SOURCE_REASON_APPLY_FRIEND = 0;
    const SOURCE_REASON_WRITE_POST = 1;
    const SOURCE_REASON_PROMOTION = 2;
    const SOURCE_REASON_FULL_INFO = 3;
    const SOURCE_REASON_BIND_MOBILE = 4;    
    const SOURCE_REASON_SYSTEM_AUTO_SEND_MONEY = 5;    
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'mkt_gold';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['user_id', 'source'], 'integer'],
            [['amount'], 'number'],
            [['create_time'], 'safe'],
            [['memo'], 'string', 'max' => 32],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => '用户编号',
            'amount' => '发生额',
            'memo' => '备注',
            'create_time' => '时间',
            'source' => '来源', //0:补全, 1:发贴, 2:推广
        ];
    }


    static function getGoldSourceOption($key=null)
    {
        $arr = array(
            self::SOURCE_REASON_APPLY_FRIEND => '加好友',
            self::SOURCE_REASON_WRITE_POST => '发布贴子',
            self::SOURCE_REASON_PROMOTION => '分享推广',
            self::SOURCE_REASON_FULL_INFO => '补全信息',
            self::SOURCE_REASON_BIND_MOBILE => '绑定手机',            
            self::SOURCE_REASON_SYSTEM_AUTO_SEND_MONEY => '系统自动赠送',                                    
        );
        return $key === null ? $arr : (isset($arr[$key]) ? $arr[$key] : '');
    }


    /**
     * @inheritdoc
     * @return MktGoldQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new MktGoldQuery(get_called_class());
    }
}
